home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Presentations / Presentations ’97 / Sessions ’97 / Multiplatform Code⁄Data Sharing / HelloBothWorlds / Shared / CGEView.cpp next >
Encoding:
C/C++ Source or Header  |  1997-06-26  |  1.7 KB  |  87 lines  |  [TEXT/CWIE]

  1. /*
  2.     CGEView.cpp
  3.     
  4.     Demo cross-platform view class for MacHack '97
  5.         
  6.     Al Evans
  7.     
  8.     6/12/97
  9.     
  10. */
  11.  
  12. #include "CGEView.h"
  13. #include "CDemoWindow.h"
  14. #include "DemoConversions.h"
  15. #include "DemoGraphicTypes.h"
  16. #include "GEWmgr.h"
  17. #include "UnivPictLoader.h"
  18. #include "reschain.h"
  19.  
  20.  
  21. CGEView::CGEView(CDemoWindow *owner, int32 viewResID)
  22.         :mOwner(owner), mGEWorld(nil)
  23. {
  24.     // Read view definition from resource
  25.     void* vLayoutRes = GetResourcePtr('Vnfo', viewResID);
  26.     assert( vLayoutRes );
  27.     ViewLayout layout = *(ViewLayout *) vLayoutRes;
  28.     ReleaseResourcePtr( vLayoutRes );
  29.     
  30.     SwapIfRequired(&layout);
  31.     
  32.     mGEWorld = NewGEWorld( (GrafPtr) mOwner->GetSystemWindow(), 
  33.                     &mOwner->GetWindRect(), scaleOneToOne, mOwner->GetPalette());
  34.     if (mGEWorld) {
  35.         (void) AddToWorldList(mGEWorld, true);
  36.         
  37.         // Set Graphic Elements to use "universal pictures" instead of PICTs
  38.         mGEWorld->defaultLoader = LoadUnivPictElement;
  39.         
  40.         // If this were a real program, we'd resize the window here to
  41.         // layout.viewSize
  42.         
  43.         if (layout.viewBkgID != 0)
  44.             MakeNewBackground(mGEWorld, layout.viewBkgID);
  45.         if (layout.viewBouncerID != 0)
  46.             MakeNewBouncer(mGEWorld, layout.viewBouncerID);
  47.         if (layout.viewBtnID != 0)
  48.             MakeNewBtn(mGEWorld, layout.viewBtnID);
  49.     }
  50.  
  51.     
  52. }
  53.  
  54. CGEView::~CGEView()
  55. {
  56.     if (mGEWorld)
  57.         DisposeGEWorld(mGEWorld);
  58. }
  59.  
  60. void CGEView::Activate(Boolean activateIt) 
  61.     if (mGEWorld) 
  62.         ActivateWorld(mGEWorld, activateIt); 
  63. }
  64.  
  65. void CGEView::Idle() 
  66. {
  67.     if (mGEWorld) 
  68.         Update1GEWorld(mGEWorld, false); 
  69. }
  70.  
  71. void CGEView::Draw() 
  72. {
  73.     if (mGEWorld) DoWorldUpdate(mGEWorld, true); 
  74. }
  75.  
  76. void CGEView::HandleMouseDown(Point mousePt)
  77. {
  78.     if (mGEWorld) {
  79. #if TARGET_IS_WIN95
  80.         ::ClientToScreen(mOwner->GetSafeHwnd(), &mousePt.WinPoint);
  81. #endif
  82.         MouseDownInSensor(mGEWorld, mousePt); 
  83.     }
  84. }
  85.  
  86.